use "$temp/acs_longform_merged_clean", clear 
keep if dby>=1990 //restrict to at-risk sample
tab age_group parent_inc_quart

//final cleaning
replace coll = 0 if age_group == 1
replace assoc = 0 if age_group == 0
drop if parent_inc_quart == .  //nix matched kids with no parent income

local vars `"coll assoc somecoll enroll"'
foreach var in `vars'{
	preserve
	local controls `"cz_shock sex asian black hispan i.year i.state_2000#i.head_coll i.age_group head_mar head_constr_manu house_value parent_inc own_house"'
	reg `var' c.cz_shock#i.age_group `controls' [aw = weight], vce(cluster cz_2000)

	//graphing
	forval i = 1/4{
		local effect_`i' = round(_b[`i'.age_group#c.cz_shock], 0.001)
		local se_`i' = round(_se[`i'.age_group#c.cz_shock], 0.001)
		su `var' [aw = weight] if age_group == `i' 
		local mean_`i' = round(`r(mean)', 0.01)
	}

	clear
	set obs 4
	gen group = .
	gen effect = .
	gen se = .
	gen mean = .
	forval i = 1/4{
		replace group = `i' in `i'
		replace effect = `effect_`i'' in `i'
		replace se = `se_`i'' in `i'
		replace mean = `mean_`i'' in `i'
	}

	//upper, lower bounds
	gen ub = effect + 1.96*se
	gen lb = effect - 1.96*se
	
	local lab1 = 40
	if "`var'" == "assoc"{
		local lab1 = 50
	}
	if "`var'" == "somecoll"{
		local lab1 = 80
	}
	if "`var'" == "enroll"{
		local lab1 = 90
	}
	local lab2 = `lab1'/2

	//fancy graph
	twoway connected effect group, graphregion(color(white)) bgcolor(white) ylabel(-3(1.5)3, angle(0) grid) ///
	xlabel(1 "17-19" 2 "20-22" 3 "23-25" 4 "26-28") xtitle("Age Group") ytitle("Effect") lc(black) mc(black) ///
	|| line ub group, lp(dash) lc(black) || line lb group, lp(dash) lc(black) ///
	|| connected mean group, yaxis(2) ytitle("Basis", axis(2)) ylabel(-`lab1'(`lab2')`lab1', axis(2) angle(0) grid) ms(T) mc(black) lc(black) ///
	legend(order(1 "Effect" 4 "Basis")) yline(0)
	graph export "$disc/3_effects_`var'_fullsample.png", replace width(1500)
	restore
}


***********************wage income***********************
use "$temp/acs_longform_merged_clean", clear
keep if dby>=1990 //restrict to at-risk sample
drop if parent_inc_quart == .  //nix matched kids with no parent income

cap drop age_group
gen age_group = 0
replace age_group = 1 if age>=17 & age<=19
replace age_group = 2 if age>=20 & age<=22
replace age_group = 3 if age>=23 & age<=25
replace age_group = 4 if age>=26 & age<=28
replace wag = wag/1000
replace ti = . if wag == . 
replace wag = . if ti == . 

//base
local controls `"cz_shock sex asian black hispan i.year i.state_2000#i.head_coll i.age_group head_mar head_constr_manu house_value parent_inc own_house"'
reg wag c.cz_shock#i.age_group `controls' [aw = weight], vce(cluster cz_2000)

//graphing
forval i = 1/4{
	local effect_`i' = round(_b[`i'.age_group#c.cz_shock], 0.001)*1000
	local se_`i' = round(_se[`i'.age_group#c.cz_shock], 0.001)*1000
	su wag [aw = weight] if age_group == `i' 
	local mean_`i' = round(`r(mean)', 0.01)*1000
}

clear
set obs 4
gen group = .
gen effect = .
gen se = .
gen mean = .
forval i = 1/4{
	replace group = `i' in `i'
	replace effect = `effect_`i'' in `i'
	replace se = `se_`i'' in `i'
	replace mean = `mean_`i'' in `i'
}

//upper, lower bounds
gen ub = effect + 1.96*se
gen lb = effect - 1.96*se

//fancy graph
twoway connected effect group, graphregion(color(white)) bgcolor(white) ylabel(-1000(500.0)1000, angle(0) grid) ///
xlabel(1 "17-19" 2 "20-22" 3 "23-25" 4 "26-28") xtitle("Age Group") ytitle("Effect") lc(black) mc(black) ///
|| line ub group, lp(dash) lc(black) || line lb group, lp(dash) lc(black) ///
|| connected mean group, yaxis(2) ytitle("Basis", axis(2)) ylabel(-40000(20000)40000, axis(2) angle(0) grid) ms(T) mc(black) lc(black) ///
legend(order(1 "Effect" 4 "Basis")) yline(0)
graph export "$disc/3_effects_wag_fullsample.png", replace width(1500)
graph close
